/* GUI CONVERTED from ececrp03.p (converter v1.76) Thu Nov 21 03:06:04 2002 */
/* ececrp03.p - ECN PRINT SUB-ROUTING: PRODUCT STRUCTURE REPORT               */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                        */
/* All rights reserved worldwide.  This is an unpublished work.               */
/* $Revision: 1.7.1.7 $                                                           */
/*                                                                            */
/*V8:ConvertMode=Report                                                       */
/* REVISION: 7.4  LAST EDIT: 04/20/95       MODIFIED BY: QZL *H0D4            */
/* REVISION: 7.4  LAST EDIT: 04/20/95       MODIFIED BY: QZL *H0DB            */
/* REVISION: 8.6  LAST EDIT: 06/06/96       MODIFIED BY: Mariya Kutwal *K00C* */
/* REVISION: 8.6  LAST EDIT: 04/01/97       MODIFIED BY: Joe Gawel     *K08X* */
/* REVISION: 8.6  LAST EDIT: 10/20/97       MODIFIED BY: mur *K136*           */
/* REVISION: 8.6E LAST MODIFIED: 02/23/98   BY: *L007* A. Rahane              */
/* REVISION: 8.6E LAST MODIFIED: 10/04/98   BY: *J314* Alfred Tan             */
/* REVISION: 8.6E LAST MODIFIED: 02/01/99   BY: *K1Z2* Santhosh Nair          */
/* REVISION: 9.1  LAST MODIFIED: 03/24/00   BY: *N08T* Annasaheb Rahane       */
/* REVISION: 9.1  LAST MODIFIED: 04/17/00   BY: *N07D* Antony Babu            */
/* REVISION: 9.1  LAST MODIFIED: 08/14/00   BY: *N0KW* Jacolyn Neder          */
/* $Revision: 1.7.1.7 $    BY: Amit Chaturvedi  DATE: 11/15/02  ECO: *N1TM*       */
/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/


/*GUI preprocessor directive settings */
&SCOPED-DEFINE PP_GUI_CONVERT_MODE REPORT

{mfdeclre.i}
{gplabel.i} /* EXTERNAL LABEL INCLUDE */

{wbrp02.i}

define shared variable ecmnbr like ecm_nbr.

define new shared temp-table ecd1bom
   field ecd1bom_par          like bom_parent.
define variable comp          like ps_comp                            no-undo.
define variable level          as integer                             no-undo.
define variable maxlevel       as integer      format ">>>"
   label "Levels"                                                     no-undo.
define variable parent        like ps_par                             no-undo.
define variable desc1         like pt_desc1    format "x(24)"         no-undo.
define variable um            like pt_um                              no-undo.
define variable phantom       like mfc_logical format "yes"
   label "Ph"                                                         no-undo.
define variable iss_pol       like pt_iss_pol  format "/no"           no-undo.
define variable record          as integer     extent 100             no-undo.
define variable lvl             as character   format "x(10)"
   label "Level"                                                      no-undo.
define variable new_parent    like mfc_logical                        no-undo.
define variable lines           as integer                            no-undo.
define variable first_stru      as logical                            no-undo.
define variable formula_yn      as logical                            no-undo.
define variable i               as integer                            no-undo.

define input parameter l_doc_type like ecm_doc_type.

/* TEMP-TABLE TO STORE THE PRODUCT STRUCTURE THAT ARE PRINTED */
define temp-table t_ecd1_det no-undo
   field t_ecd1_par  like ecd1_par
   field t_ecd1_comp like ecd1_comp.

/* MOVED FRAME DEFINATION FROM BELOW */
/* DETAIL FORM */
FORM /*GUI*/ 
   lvl               colon 5
   ecd1_comp
   ecd1_ref
   desc1
   ps_qty_per        column-label "Current!Qty Per"
   um
   phantom
   iss_pol
   ecd1_qty_per_b    column-label "PCC    !Qty Per"
   ecd1_qty_type     column-label "Qty!Type"
   ecd1__qad03       format "x(1)" column-label "Stru!Type"
with STREAM-IO /*GUI*/  frame det2
   width 132
   no-attr-space
   no-box.

/* SET EXTERNAL LABELS */
setFrameLabels(frame det2:handle).

{gprun.i ""ececrp3a.p""}

first_stru = yes.

for each ecd1bom:

   if first_stru
   then do:

      put space(132).
   end. /* IF first_stru */

   assign
      comp     = ecd1bom_par
      maxlevel = min(maxlevel,99)
      level    = 1.

   for first ecd1_det
      fields(ecd1_batch ecd1_cmtindx   ecd1_comp     ecd1_nbr
             ecd1_par   ecd1_qty_per_b ecd1_qty_type ecd1_ref
             ecd1_rmks  ecd1__qad01    ecd1__qad03)
      use-index ecd1_par_comp
      where ecd1_nbr = ecmnbr
        and ecd1_par = comp
      no-lock:
   end. /* FOR FIRST ecd1_det */

   if not available ecd1_det
   then
      next.

   for first pt_mstr
      fields(pt_desc1 pt_desc2 pt_iss_pol pt_part pt_phantom pt_um)
      where pt_part = comp
      no-lock:
   end. /* FOR FIRST pt_mstr */

   for first bom_mstr
      fields(bom_batch bom_batch_um bom_desc bom_parent)
      where bom_parent = comp
      no-lock:
   end. /* FOR FIRST bom_mstr */

   assign
      parent     = ecd1_par
      phantom    = if available pt_mstr
                   then
                      pt_phantom
                   else
                      no
      new_parent = yes.

   repeat with frame det2 down:

      if new_parent = yes
      then do:

         formula_yn = no.

         if not first_stru
         then
            down 1.

         display
            caps(getTermLabel("PARENT",10)) @ lvl
            parent @ ecd1_comp
            pt_desc1 when (available pt_mstr) @ desc1
            bom_desc when (not available pt_mstr) @ desc1
            pt_um when (available pt_mstr) @ um
            bom_batch_um when (not available pt_mstr) @ um
            phantom @ phantom WITH STREAM-IO /*GUI*/ .

         if available bom_mstr
         and bom_batch <> 0
         and bom_batch <> 1
         then do:

            display
               space(1) getTermLabelRtColon("BATCH_QTY",10) @ ps_qty_per
               trim(string(bom_batch)) @ ecd1_qty_per_b WITH STREAM-IO /*GUI*/ .

            formula_yn = yes.
         end. /* IF AVAILABLE bom_mstr */

         down 1.

         if available pt_mstr
         and pt_desc2 > ""
         then do:

            display
               pt_desc2 @ desc1 WITH STREAM-IO /*GUI*/ .
            down 1.
         end. /* IF AVAILABLE pt_mstr */

         new_parent = no.
      end. /* IF new_parent = yes */

      if not available ecd1_det
      then do:

         repeat:
            level = level - 1.
            if level < 1
            then
               leave.
            for first ecd1_det
               fields(ecd1_batch ecd1_cmtindx   ecd1_comp     ecd1_nbr
                      ecd1_par   ecd1_qty_per_b ecd1_qty_type ecd1_ref
                      ecd1_rmks  ecd1__qad01    ecd1__qad03)
               where recid(ecd1_det) = record[level]
               no-lock:
            end. /* FOR FIRST ecd1_det */

            comp = ecd1_par.

            find next ecd1_det
               use-index ecd1_par_comp
               where ecd1_nbr = ecmnbr
                 and ecd1_par = comp
               no-lock
               no-error.
            if available ecd1_det
            then
               leave.
         end. /* REPEAT */
      end. /* IF NOT AVAILABLE ecd1_det */

      if level < 1
      then
         leave.

      assign um  = ""
         desc1   = ""
         iss_pol = no
         phantom = no.

      for first pt_mstr
         fields(pt_desc1 pt_desc2 pt_iss_pol pt_part pt_phantom pt_um)
         where pt_part = ecd1_comp
         no-lock:
         assign um  = pt_um
            desc1   = pt_desc1
            iss_pol = pt_iss_pol
            phantom = pt_phantom.
      end. /* FOR FIRST pt_mstr */

      if not available pt_mstr
      then do:

         for first bom_mstr
            fields(bom_batch bom_batch_um bom_desc bom_parent)
            where bom_parent = ecd1_comp
            no-lock:
            assign
               um    = bom_batch_um
               desc1 = bom_desc.
         end. /* FOR FIRST bom_mstr */
      end. /* IF NOT AVAILABLE pt_mstr */

      assign
         record[level] = recid(ecd1_det)
         lvl           = "........"
         lvl           = substring(lvl,1,min (level - 1,9)) + string(level).

      if length(lvl) > 10
      then
         lvl = substring(lvl,length (lvl) - 9,10).

      lines = 1.

      if ecd1_rmks > ""
      then
         lines = lines + 1.

      if available pt_mstr
      and pt_desc2 > ""
      then
         lines = lines + 1.

      if page-size - line-counter < lines
      then
         page.

      for first ps_mstr
         fields(ps_comp ps_end ps_par ps_qty_per ps_qty_per_b ps_ref ps_start)
         where ps_par     = ecd1_par
           and ps_comp    = ecd1_comp
           and ps_ref     = ecd1_ref
           and (ps_start <= today
            or  ps_start  = ?)
           and (ps_end   >= today
            or ps_end     = ?)
         no-lock:
      end. /* FOR FIRST ps_mstr */

      display
         lvl
         ecd1_comp
         ecd1_ref
         desc1
         ps_qty_per     when (available ps_mstr and not formula_yn)
         ps_qty_per_b   when (available ps_mstr and formula_yn) @ ps_qty_per
         ecd1_qty_per_b when (ecd1__qad01 = no and formula_yn)
         ecd1_qty_per_b / (if ecd1_batch <> 0
                           then
                              ecd1_batch
                           else
                              1)
                        when (ecd1__qad01 = no
                         and not formula_yn) @ ecd1_qty_per_b
         ecd1_qty_type
         um
         phantom
         ecd1__qad03
         iss_pol
      with frame det2 STREAM-IO /*GUI*/ .

      if ecd1__qad01
      then
         display
            space(1)
            caps(getTermLabel("DEACTIVATED",11)) @ ecd1_qty_per_b WITH STREAM-IO /*GUI*/ .

      down 1 with frame det2.

      if available pt_mstr
      and pt_desc2 > ""
      then do:

         display
            pt_desc2 @ desc1 WITH STREAM-IO /*GUI*/ .
         down 1 with frame det2.
      end. /* IF AVAILABLE pt_mstr */

      if length(ecd1_rmks) <> 0
      then do:

         display
            ecd1_rmks @ desc1 WITH STREAM-IO /*GUI*/ .
         down 1 with frame det2.
      end. /* IF length(ecd1_rmks) <> 0 */

      /* STORE THE PRINTED PRODUCT STRUCTURE */
      if not can-find(first t_ecd1_det
         where t_ecd1_par  = ecd1_par
           and t_ecd1_comp = ecd1_comp)
      then do:

         create t_ecd1_det.
         assign
            t_ecd1_par  = ecd1_par
            t_ecd1_comp = ecd1_comp .
      end. /* IF NOT CAN-FIND(FIRST t_ecd1_det ... */

      if level < maxlevel
      or maxlevel = 0
      then do:

         assign
            comp  = ecd1_comp
            level = level + 1.

         for first ecd1_det
            fields(ecd1_batch ecd1_cmtindx   ecd1_comp     ecd1_nbr
                   ecd1_par   ecd1_qty_per_b ecd1_qty_type ecd1_ref
                   ecd1_rmks  ecd1__qad01    ecd1__qad03)
            use-index
            ecd1_par_comp
            where ecd1_nbr = ecmnbr
              and ecd1_par = comp
            no-lock:
         end. /* FOR FIRST ecd1_det */
      end. /* IF level < maxlevel */
      else do:

         find next ecd1_det
            use-index ecd1_par_comp
            where ecd1_nbr = ecmnbr
              and ecd1_par = comp
            no-lock
            no-error.
      end. /* ELSE DO, IF level < mexlevel */
   end. /* REPEAT WITH FRAME det2 DOWN */

   first_stru = no.
end. /* FOR EACH ecd1bom */

/* BEGIN ADD SECTION */

first_stru = yes.
/* PRINT ALL THE CYCLIC PRODUCT STRUCTURES */
for each ecd1_det
   fields(ecd1_batch ecd1_cmtindx   ecd1_comp     ecd1_nbr
          ecd1_par   ecd1_qty_per_b ecd1_qty_type ecd1_ref
          ecd1_rmks  ecd1__qad01    ecd1__qad03)
   where ecd1_nbr = ecmnbr
     and not can-find(first t_ecd1_det
                where t_ecd1_par  = ecd1_par
                and   t_ecd1_comp = ecd1_comp)
   no-lock
   break by ecd1_par
   with frame det2:

   if first_stru
   then do:

      /* PRODUCT STRUCTURES WITH CIRCULAR REFERENCING IN THIS PCO/PCR */
      {pxmsg.i &MSGNUM=5777 &ERRORLEVEL=1 &MSGARG1=l_doc_type}

      first_stru = no.
   end. /* IF first_stru */

   lvl = "PARENT".
   if page-size - line-counter < 6
   then
      page.

   for first pt_mstr
      fields(pt_desc1 pt_desc2 pt_iss_pol pt_part pt_phantom pt_um)
      where pt_part = ecd1_comp
      no-lock:
   end. /* FOR FIRST pt_mstr */

   for first bom_mstr
      fields(bom_batch bom_batch_um bom_desc bom_parent)
      where bom_parent = ecd1_comp
      no-lock:
   end. /* FOR FIRST bom_mstr */

   if first-of(ecd1_par)
   then do:

      if page-size - line-counter < 4
      then
         page.

      /* DISPLAY PARENT */
      display
         caps(getTermLabel("PARENT",10))           @ lvl
         ecd1_par                                  @ ecd1_comp
         pt_desc1 when (available pt_mstr)         @ desc1
         bom_desc when (not available pt_mstr)     @ desc1
         pt_um when (available pt_mstr)            @ um
         bom_batch_um when (not available pt_mstr) @ um
         phantom                                   @ phantom
      with frame det2  STREAM-IO /*GUI*/ .

      if available bom_mstr
      and bom_batch <> 0
      and bom_batch <> 1
      then do:

         display
            space(1)
            getTermLabelRtColon("BATCH_QTY",10) @ ps_qty_per
            trim(string(bom_batch))             @ ecd1_qty_per_b
         with frame det2 STREAM-IO /*GUI*/ .

         down 1 with frame det2.
      end. /* IF AVAILABLE bom_mstr */

      if available pt_mstr
      and pt_desc2 > ""
      then do:

         display
            pt_desc2 @ desc1
         with frame det2 STREAM-IO /*GUI*/ .
      end. /* IF AVAILABLE pt_mstr */

      down 1 with frame det2.

   end. /* IF FIRST-OF(ecd1_par) */

   /* DISPLAY COMPONENTS FOR PARENT */
   lvl = "1".
   display
      lvl
      ecd1_comp
      ecd1_ref
      desc1
      ecd1_qty_per_b when (ecd1__qad01 = no
                      and formula_yn)
      ecd1_qty_per_b / (if ecd1_batch <> 0
                        then
                           ecd1_batch
                        else
                           1)
                     when (ecd1__qad01 = no
                     and not formula_yn) @ ecd1_qty_per_b
      ecd1_qty_type
      um
      phantom
      ecd1__qad03
      iss_pol
   with frame det2 down STREAM-IO /*GUI*/ .
end. /* FOR EACH ecd1_det */

/* END ADD SECTION */

for each ecd1_det
   fields(ecd1_batch ecd1_cmtindx   ecd1_comp     ecd1_nbr
          ecd1_par   ecd1_qty_per_b ecd1_qty_type ecd1_ref
          ecd1_rmks  ecd1__qad01    ecd1__qad03)
   no-lock
   where ecd1_nbr = ecmnbr
     and can-find(first cmt_det
            where cmt_indx = ecd1_cmtindx)
with frame ecd1cmt
width 132
no-label
no-attr-space no-box:

   put space(132) skip.

   put {gplblfmt.i &FUNC=getTermLabel(""PARENT"",9)
      &CONCAT="': '"
      } at 27
      ecd1_par + " " +
      {gplblfmt.i &FUNC=getTermLabel(""COMPONENT"",12)
      &CONCAT="': '"
      }
      ecd1_comp + " " +
      {gplblfmt.i &FUNC=getTermLabel(""REFERENCE"",5)
      &CONCAT="': '"
      }
      ecd1_ref skip.

   put space(132) skip.

   for each cmt_det
      fields(cmt_cmmt cmt_indx)
      no-lock
      where cmt_indx = ecd1_cmtindx
      with frame ecd1cmt:

      do i = 1 to 15:

         if cmt_cmmt[i] <> ""
         then
            put cmt_cmmt[i] at 27 skip.
      end. /* DO i = 1 TO 15 */
      put space(132) skip.
   end. /* FOR EACH cmt_det */
   put space(132) skip.
end. /* FOR EACH ecd1_det ... */

{wbrp04.i}
